#if !defined(_APP_BUFFER)
#define _APP_BUFFER
#include <pthread.h>

typedef struct 
{
    char *ptr;
    int  total_size;
    int  offset;
    int  len;
    pthread_mutex_t lock;
}Buffer;
 

/**
 * @brief  初始化buffer
 * @return c缓冲区
 *
 */
Buffer *app_buffer_init( int total_size);

/**
 * 写入数据
 * @return   0:成功  -1:失败
 */
int app_buffer_write(Buffer *buffer, const char *write_data, int write_len);

/**
 * 读取数据
 * @return     -1:失败   非负 实际读取长度
 */
int app_buffer_read(Buffer *buffer, char *read_buffer, int read_len);


/**
 * 释放buffer
 */
void app_buffer_free(Buffer *buffer);


#endif // MACRO


